<html>
<head>
  <title>../ex11.c</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<a href="../ex11.c">download the original source code</a>.
<pre>
<a name="line1">  1</a> <font color="#444444">/*
<a name="line2">  2</a>    Example 11
<a name="line3">  3</a> 
<a name="line4">  4</a>    Interface:    Linear-Algebraic (IJ)
<a name="line5">  5</a> 
<a name="line6">  6</a>    Compile with: make ex11
<a name="line7">  7</a> 
<a name="line8">  8</a>    Sample run:   mpirun -np 4 ex11
<a name="line9">  9</a> 
<a name="line10"> 10</a>    Description:  This example solves the 2-D Laplacian eigenvalue
<a name="line11"> 11</a>                  problem with zero boundary conditions on an nxn grid.
<a name="line12"> 12</a>                  The number of unknowns is N=n^2. The standard 5-point
<a name="line13"> 13</a>                  stencil is used, and we solve for the interior nodes
<a name="line14"> 14</a>                  only.
<a name="line15"> 15</a> 
<a name="line16"> 16</a>                  We use the same matrix as in Examples 3 and 5.
<a name="line17"> 17</a>                  The eigensolver is LOBPCG with AMG preconditioner.
<a name="line18"> 18</a> */</font>
<a name="line19"> 19</a> 
<a name="line20"> 20</a> <font color="0000ff"><strong>#include <font color="#008000">&lt;math.h&gt;</font></strong></font>
<a name="line21"> 21</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;_hypre_utilities.h&quot;</font></strong></font>
<a name="line22"> 22</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;krylov.h&quot;</font></strong></font>
<a name="line23"> 23</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;HYPRE.h&quot;</font></strong></font>
<a name="line24"> 24</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;HYPRE_parcsr_ls.h&quot;</font></strong></font>
<a name="line25"> 25</a> 
<a name="line26"> 26</a> <font color="#444444">/* lobpcg stuff */</font>
<a name="line27"> 27</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;HYPRE_lobpcg.h&quot;</font></strong></font>
<a name="line28"> 28</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;interpreter.h&quot;</font></strong></font>
<a name="line29"> 29</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;HYPRE_MatvecFunctions.h&quot;</font></strong></font>
<a name="line30"> 30</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;temp_multivector.h&quot;</font></strong></font>
<a name="line31"> 31</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;_hypre_parcsr_mv.h&quot;</font></strong></font>
<a name="line32"> 32</a> 
<a name="line33"> 33</a> <font color="0000ff"><strong>#include <font color="#008000">&quot;vis.c&quot;</font></strong></font>
<a name="line34"> 34</a> 
<a name="line35"> 35</a> <strong>int</strong> <font color="#2040a0">main</font> <font color="4444FF">(</font><strong>int</strong> <font color="#2040a0">argc</font>, <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="4444FF">]</font><font color="4444FF">)</font>
<a name="line36"> 36</a> <font color="4444FF"><strong>{</strong></font>
<a name="line37"> 37</a>    <strong>int</strong> <font color="#2040a0">i</font><font color="4444FF">;</font>
<a name="line38"> 38</a>    <strong>int</strong> <font color="#2040a0">myid</font>, <font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line39"> 39</a>    <strong>int</strong> <font color="#2040a0">N</font>, <font color="#2040a0">n</font><font color="4444FF">;</font>
<a name="line40"> 40</a>    <strong>int</strong> <font color="#2040a0">blockSize</font><font color="4444FF">;</font>
<a name="line41"> 41</a> 
<a name="line42"> 42</a>    <strong>int</strong> <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font><font color="4444FF">;</font>
<a name="line43"> 43</a>    <strong>int</strong> <font color="#2040a0">local_size</font>, <font color="#2040a0">extra</font><font color="4444FF">;</font>
<a name="line44"> 44</a> 
<a name="line45"> 45</a>    <strong>int</strong> <font color="#2040a0">vis</font><font color="4444FF">;</font>
<a name="line46"> 46</a> 
<a name="line47"> 47</a>    <strong>double</strong> <font color="#2040a0">h</font>, <font color="#2040a0">h2</font><font color="4444FF">;</font>
<a name="line48"> 48</a> 
<a name="line49"> 49</a>    <font color="#2040a0">HYPRE_IJMatrix</font> <font color="#2040a0">A</font><font color="4444FF">;</font>
<a name="line50"> 50</a>    <font color="#2040a0">HYPRE_ParCSRMatrix</font> <font color="#2040a0">parcsr_A</font><font color="4444FF">;</font>
<a name="line51"> 51</a>    <font color="#2040a0">HYPRE_IJVector</font> <font color="#2040a0">b</font><font color="4444FF">;</font>
<a name="line52"> 52</a>    <font color="#2040a0">HYPRE_ParVector</font> <font color="#2040a0">par_b</font><font color="4444FF">;</font>
<a name="line53"> 53</a>    <font color="#2040a0">HYPRE_IJVector</font> <font color="#2040a0">x</font><font color="4444FF">;</font>
<a name="line54"> 54</a>    <font color="#2040a0">HYPRE_ParVector</font> <font color="#2040a0">par_x</font><font color="4444FF">;</font>
<a name="line55"> 55</a>    <font color="#2040a0">HYPRE_ParVector</font><font color="4444FF">*</font> <font color="#2040a0">pvx</font><font color="4444FF">;</font>
<a name="line56"> 56</a> 
<a name="line57"> 57</a>    <font color="#2040a0">HYPRE_Solver</font> <font color="#2040a0">precond</font>, <font color="#2040a0">lobpcg_solver</font><font color="4444FF">;</font>
<a name="line58"> 58</a>    <font color="#2040a0">mv_InterfaceInterpreter</font><font color="4444FF">*</font> <font color="#2040a0">interpreter</font><font color="4444FF">;</font>
<a name="line59"> 59</a>    <font color="#2040a0">HYPRE_MatvecFunctions</font> <font color="#2040a0">matvec_fn</font><font color="4444FF">;</font>
<a name="line60"> 60</a> 
<a name="line61"> 61</a>    <font color="#444444">/* Initialize MPI */</font>
<a name="line62"> 62</a>    <font color="#2040a0">MPI_Init</font><font color="4444FF">(</font><font color="4444FF">&amp;</font><font color="#2040a0">argc</font>, <font color="4444FF">&amp;</font><font color="#2040a0">argv</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line63"> 63</a>    <font color="#2040a0">MPI_Comm_rank</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="4444FF">&amp;</font><font color="#2040a0">myid</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line64"> 64</a>    <font color="#2040a0">MPI_Comm_size</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="4444FF">&amp;</font><font color="#2040a0">num_procs</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line65"> 65</a> 
<a name="line66"> 66</a>    <font color="#444444">/* Default problem parameters */</font>
<a name="line67"> 67</a>    <font color="#2040a0">n</font> <font color="4444FF">=</font> <font color="#FF0000">33</font><font color="4444FF">;</font>
<a name="line68"> 68</a>    <font color="#2040a0">blockSize</font> <font color="4444FF">=</font> <font color="#FF0000">10</font><font color="4444FF">;</font>
<a name="line69"> 69</a>    <font color="#2040a0">vis</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line70"> 70</a> 
<a name="line71"> 71</a>    <font color="#444444">/* Parse command line */</font>
<a name="line72"> 72</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line73"> 73</a>       <strong>int</strong> <font color="#2040a0">arg_index</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line74"> 74</a>       <strong>int</strong> <font color="#2040a0">print_usage</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line75"> 75</a> 
<a name="line76"> 76</a>       <strong>while</strong> <font color="4444FF">(</font><font color="#2040a0">arg_index</font> <font color="4444FF">&lt;</font> <font color="#2040a0">argc</font><font color="4444FF">)</font>
<a name="line77"> 77</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line78"> 78</a>          <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">strcmp</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">]</font>, <font color="#008000">&quot;-n&quot;</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font>
<a name="line79"> 79</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line80"> 80</a>             <font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line81"> 81</a>             <font color="#2040a0">n</font> <font color="4444FF">=</font> <font color="#2040a0">atoi</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line82"> 82</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line83"> 83</a>          <strong>else</strong> <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">strcmp</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">]</font>, <font color="#008000">&quot;-blockSize&quot;</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font>
<a name="line84"> 84</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line85"> 85</a>             <font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line86"> 86</a>             <font color="#2040a0">blockSize</font> <font color="4444FF">=</font> <font color="#2040a0">atoi</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line87"> 87</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line88"> 88</a>          <strong>else</strong> <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">strcmp</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">]</font>, <font color="#008000">&quot;-vis&quot;</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font>
<a name="line89"> 89</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line90"> 90</a>             <font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line91"> 91</a>             <font color="#2040a0">vis</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line92"> 92</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line93"> 93</a>          <strong>else</strong> <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">strcmp</font><font color="4444FF">(</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#2040a0">arg_index</font><font color="4444FF">]</font>, <font color="#008000">&quot;-help&quot;</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font>
<a name="line94"> 94</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line95"> 95</a>             <font color="#2040a0">print_usage</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line96"> 96</a>             <strong>break</strong><font color="4444FF">;</font>
<a name="line97"> 97</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line98"> 98</a>          <strong>else</strong>
<a name="line99"> 99</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line100">100</a>             <font color="#2040a0">arg_index</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line101">101</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line102">102</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line103">103</a> 
<a name="line104">104</a>       <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">print_usage</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="4444FF">&amp;</font> <font color="4444FF">(</font><font color="#2040a0">myid</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">)</font><font color="4444FF">)</font>
<a name="line105">105</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line106">106</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line107">107</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;Usage: %s [&lt;options&gt;]<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line108">108</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line109">109</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;  -n &lt;n&gt;              : problem size in each direction (default: 33)<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line110">110</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;  -blockSize &lt;n&gt;      : eigenproblem block size (default: 10)<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line111">111</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;  -vis                : save the solution for GLVis visualization<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line112">112</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;<font color="#77dd77">\n</font>&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line113">113</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line114">114</a> 
<a name="line115">115</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">print_usage</font><font color="4444FF">)</font>
<a name="line116">116</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line117">117</a>          <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line118">118</a>          <strong>return</strong> <font color="4444FF">(</font><font color="#FF0000">0</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line119">119</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line120">120</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line121">121</a> 
<a name="line122">122</a>    <font color="#444444">/* Preliminaries: want at least one processor per row */</font>
<a name="line123">123</a>    <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">n</font><font color="4444FF">*</font><font color="#2040a0">n</font> <font color="4444FF">&lt;</font> <font color="#2040a0">num_procs</font><font color="4444FF">)</font> <font color="#2040a0">n</font> <font color="4444FF">=</font> <font color="#2040a0">sqrt</font><font color="4444FF">(</font><font color="#2040a0">num_procs</font><font color="4444FF">)</font> <font color="4444FF">+</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line124">124</a>    <font color="#2040a0">N</font> <font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">*</font><font color="#2040a0">n</font><font color="4444FF">;</font> <font color="#444444">/* global number of rows */</font>
<a name="line125">125</a>    <font color="#2040a0">h</font> <font color="4444FF">=</font> <font color="#FF0000">1.0</font>/<font color="4444FF">(</font><font color="#2040a0">n</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font> <font color="#444444">/* mesh size*/</font>
<a name="line126">126</a>    <font color="#2040a0">h2</font> <font color="4444FF">=</font> <font color="#2040a0">h</font><font color="4444FF">*</font><font color="#2040a0">h</font><font color="4444FF">;</font>
<a name="line127">127</a> 
<a name="line128">128</a>    <font color="#444444">/* Each processor knows only of its own rows - the range is denoted by ilower
<a name="line129">129</a>       and iupper.  Here we partition the rows. We account for the fact that
<a name="line130">130</a>       N may not divide evenly by the number of processors. */</font>
<a name="line131">131</a>    <font color="#2040a0">local_size</font> <font color="4444FF">=</font> <font color="#2040a0">N</font>/<font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line132">132</a>    <font color="#2040a0">extra</font> <font color="4444FF">=</font> <font color="#2040a0">N</font> <font color="4444FF">-</font> <font color="#2040a0">local_size</font><font color="4444FF">*</font><font color="#2040a0">num_procs</font><font color="4444FF">;</font>
<a name="line133">133</a> 
<a name="line134">134</a>    <font color="#2040a0">ilower</font> <font color="4444FF">=</font> <font color="#2040a0">local_size</font><font color="4444FF">*</font><font color="#2040a0">myid</font><font color="4444FF">;</font>
<a name="line135">135</a>    <font color="#2040a0">ilower</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#2040a0">hypre_min</font><font color="4444FF">(</font><font color="#2040a0">myid</font>, <font color="#2040a0">extra</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line136">136</a> 
<a name="line137">137</a>    <font color="#2040a0">iupper</font> <font color="4444FF">=</font> <font color="#2040a0">local_size</font><font color="4444FF">*</font><font color="4444FF">(</font><font color="#2040a0">myid</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line138">138</a>    <font color="#2040a0">iupper</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#2040a0">hypre_min</font><font color="4444FF">(</font><font color="#2040a0">myid</font><font color="4444FF">+</font><font color="#FF0000">1</font>, <font color="#2040a0">extra</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line139">139</a>    <font color="#2040a0">iupper</font> <font color="4444FF">=</font> <font color="#2040a0">iupper</font> <font color="4444FF">-</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line140">140</a> 
<a name="line141">141</a>    <font color="#444444">/* How many rows do I have? */</font>
<a name="line142">142</a>    <font color="#2040a0">local_size</font> <font color="4444FF">=</font> <font color="#2040a0">iupper</font> <font color="4444FF">-</font> <font color="#2040a0">ilower</font> <font color="4444FF">+</font> <font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line143">143</a> 
<a name="line144">144</a>    <font color="#444444">/* Create the matrix.
<a name="line145">145</a>       Note that this is a square matrix, so we indicate the row partition
<a name="line146">146</a>       size twice (since number of rows = number of cols) */</font>
<a name="line147">147</a>    <font color="#2040a0">HYPRE_IJMatrixCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="4444FF">&amp;</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line148">148</a> 
<a name="line149">149</a>    <font color="#444444">/* Choose a parallel csr format storage (see the User's Manual) */</font>
<a name="line150">150</a>    <font color="#2040a0">HYPRE_IJMatrixSetObjectType</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="#2040a0">HYPRE_PARCSR</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line151">151</a> 
<a name="line152">152</a>    <font color="#444444">/* Initialize before setting coefficients */</font>
<a name="line153">153</a>    <font color="#2040a0">HYPRE_IJMatrixInitialize</font><font color="4444FF">(</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line154">154</a> 
<a name="line155">155</a>    <font color="#444444">/* Now go through my local rows and set the matrix entries.
<a name="line156">156</a>       Each row has at most 5 entries. For example, if n=3:
<a name="line157">157</a> 
<a name="line158">158</a>       A = [M -I 0; -I M -I; 0 -I M]
<a name="line159">159</a>       M = [4 -1 0; -1 4 -1; 0 -1 4]
<a name="line160">160</a> 
<a name="line161">161</a>       Note that here we are setting one row at a time, though
<a name="line162">162</a>       one could set all the rows together (see the User's Manual).
<a name="line163">163</a>    */</font>
<a name="line164">164</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line165">165</a>       <strong>int</strong> <font color="#2040a0">nnz</font><font color="4444FF">;</font>
<a name="line166">166</a>       <strong>double</strong> <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#FF0000">5</font><font color="4444FF">]</font><font color="4444FF">;</font>
<a name="line167">167</a>       <strong>int</strong> <font color="#2040a0">cols</font><font color="4444FF">[</font><font color="#FF0000">5</font><font color="4444FF">]</font><font color="4444FF">;</font>
<a name="line168">168</a> 
<a name="line169">169</a>       <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#2040a0">ilower</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">iupper</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line170">170</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line171">171</a>          <font color="#2040a0">nnz</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line172">172</a> 
<a name="line173">173</a>          <font color="#444444">/* The left identity block:position i-n */</font>
<a name="line174">174</a>          <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">-</font><font color="#2040a0">n</font><font color="4444FF">)</font><font color="4444FF">&gt;</font><font color="4444FF">=</font><font color="#FF0000">0</font><font color="4444FF">)</font>
<a name="line175">175</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line176">176</a> 	    <font color="#2040a0">cols</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">-</font><font color="#2040a0">n</font><font color="4444FF">;</font>
<a name="line177">177</a> 	    <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line178">178</a> 	    <font color="#2040a0">nnz</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line179">179</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line180">180</a> 
<a name="line181">181</a>          <font color="#444444">/* The left -1: position i-1 */</font>
<a name="line182">182</a>          <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">%</font><font color="#2040a0">n</font><font color="4444FF">)</font>
<a name="line183">183</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line184">184</a>             <font color="#2040a0">cols</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line185">185</a>             <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line186">186</a>             <font color="#2040a0">nnz</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line187">187</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line188">188</a> 
<a name="line189">189</a>          <font color="#444444">/* Set the diagonal: position i */</font>
<a name="line190">190</a>          <font color="#2040a0">cols</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">;</font>
<a name="line191">191</a>          <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">4.0</font><font color="4444FF">;</font>
<a name="line192">192</a>          <font color="#2040a0">nnz</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line193">193</a> 
<a name="line194">194</a>          <font color="#444444">/* The right -1: position i+1 */</font>
<a name="line195">195</a>          <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">%</font><font color="#2040a0">n</font><font color="4444FF">)</font>
<a name="line196">196</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line197">197</a>             <font color="#2040a0">cols</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">;</font>
<a name="line198">198</a>             <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line199">199</a>             <font color="#2040a0">nnz</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line200">200</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line201">201</a> 
<a name="line202">202</a>          <font color="#444444">/* The right identity block:position i+n */</font>
<a name="line203">203</a>          <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">+</font><font color="#2040a0">n</font><font color="4444FF">)</font><font color="4444FF">&lt;</font> <font color="#2040a0">N</font><font color="4444FF">)</font>
<a name="line204">204</a>          <font color="4444FF"><strong>{</strong></font>
<a name="line205">205</a>             <font color="#2040a0">cols</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="#2040a0">n</font><font color="4444FF">;</font>
<a name="line206">206</a>             <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#2040a0">nnz</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0</font><font color="4444FF">;</font>
<a name="line207">207</a>             <font color="#2040a0">nnz</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">;</font>
<a name="line208">208</a>          <font color="4444FF"><strong>}</strong></font>
<a name="line209">209</a> 
<a name="line210">210</a>          <font color="#444444">/* Set the values for row i */</font>
<a name="line211">211</a>          <font color="#2040a0">HYPRE_IJMatrixSetValues</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="#FF0000">1</font>, <font color="4444FF">&amp;</font><font color="#2040a0">nnz</font>, <font color="4444FF">&amp;</font><font color="#2040a0">i</font>, <font color="#2040a0">cols</font>, <font color="#2040a0">values</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line212">212</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line213">213</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line214">214</a> 
<a name="line215">215</a>    <font color="#444444">/* Assemble after setting the coefficients */</font>
<a name="line216">216</a>    <font color="#2040a0">HYPRE_IJMatrixAssemble</font><font color="4444FF">(</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line217">217</a>    <font color="#444444">/* Get the parcsr matrix object to use */</font>
<a name="line218">218</a>    <font color="#2040a0">HYPRE_IJMatrixGetObject</font><font color="4444FF">(</font><font color="#2040a0">A</font>, <font color="4444FF">(</font><strong>void</strong><font color="4444FF">*</font><font color="4444FF">*</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="#2040a0">parcsr_A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line219">219</a> 
<a name="line220">220</a>    <font color="#444444">/* Create sample rhs and solution vectors */</font>
<a name="line221">221</a>    <font color="#2040a0">HYPRE_IJVectorCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>,<font color="4444FF">&amp;</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line222">222</a>    <font color="#2040a0">HYPRE_IJVectorSetObjectType</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="#2040a0">HYPRE_PARCSR</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line223">223</a>    <font color="#2040a0">HYPRE_IJVectorInitialize</font><font color="4444FF">(</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line224">224</a>    <font color="#2040a0">HYPRE_IJVectorAssemble</font><font color="4444FF">(</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line225">225</a>    <font color="#2040a0">HYPRE_IJVectorGetObject</font><font color="4444FF">(</font><font color="#2040a0">b</font>, <font color="4444FF">(</font><strong>void</strong> <font color="4444FF">*</font><font color="4444FF">*</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="#2040a0">par_b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line226">226</a> 
<a name="line227">227</a>    <font color="#2040a0">HYPRE_IJVectorCreate</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>,<font color="4444FF">&amp;</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line228">228</a>    <font color="#2040a0">HYPRE_IJVectorSetObjectType</font><font color="4444FF">(</font><font color="#2040a0">x</font>, <font color="#2040a0">HYPRE_PARCSR</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line229">229</a>    <font color="#2040a0">HYPRE_IJVectorInitialize</font><font color="4444FF">(</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line230">230</a>    <font color="#2040a0">HYPRE_IJVectorAssemble</font><font color="4444FF">(</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line231">231</a>    <font color="#2040a0">HYPRE_IJVectorGetObject</font><font color="4444FF">(</font><font color="#2040a0">x</font>, <font color="4444FF">(</font><strong>void</strong> <font color="4444FF">*</font><font color="4444FF">*</font><font color="4444FF">)</font> <font color="4444FF">&amp;</font><font color="#2040a0">par_x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line232">232</a> 
<a name="line233">233</a>    <font color="#444444">/* Create a preconditioner and solve the eigenproblem */</font>
<a name="line234">234</a> 
<a name="line235">235</a>    <font color="#444444">/* AMG preconditioner */</font>
<a name="line236">236</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line237">237</a>       <font color="#2040a0">HYPRE_BoomerAMGCreate</font><font color="4444FF">(</font><font color="4444FF">&amp;</font><font color="#2040a0">precond</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line238">238</a>       <font color="#2040a0">HYPRE_BoomerAMGSetPrintLevel</font><font color="4444FF">(</font><font color="#2040a0">precond</font>, <font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font> <font color="#444444">/* print amg solution info */</font>
<a name="line239">239</a>       <font color="#2040a0">HYPRE_BoomerAMGSetCoarsenType</font><font color="4444FF">(</font><font color="#2040a0">precond</font>, <font color="#FF0000">6</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line240">240</a>       <font color="#2040a0">HYPRE_BoomerAMGSetRelaxType</font><font color="4444FF">(</font><font color="#2040a0">precond</font>, <font color="#FF0000">6</font><font color="4444FF">)</font><font color="4444FF">;</font> <font color="#444444">/* Sym G.S./Jacobi hybrid */</font>
<a name="line241">241</a>       <font color="#2040a0">HYPRE_BoomerAMGSetNumSweeps</font><font color="4444FF">(</font><font color="#2040a0">precond</font>, <font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line242">242</a>       <font color="#2040a0">HYPRE_BoomerAMGSetTol</font><font color="4444FF">(</font><font color="#2040a0">precond</font>, <font color="#FF0000">0.0</font><font color="4444FF">)</font><font color="4444FF">;</font> <font color="#444444">/* conv. tolerance zero */</font>
<a name="line243">243</a>       <font color="#2040a0">HYPRE_BoomerAMGSetMaxIter</font><font color="4444FF">(</font><font color="#2040a0">precond</font>, <font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font> <font color="#444444">/* do only one iteration! */</font>
<a name="line244">244</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line245">245</a> 
<a name="line246">246</a>    <font color="#444444">/* LOBPCG eigensolver */</font>
<a name="line247">247</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line248">248</a>       <strong>int</strong> <font color="#2040a0">time_index</font><font color="4444FF">;</font>
<a name="line249">249</a> 
<a name="line250">250</a>       <strong>int</strong> <font color="#2040a0">maxIterations</font> <font color="4444FF">=</font> <font color="#FF0000">100</font><font color="4444FF">;</font> <font color="#444444">/* maximum number of iterations */</font>
<a name="line251">251</a>       <strong>int</strong> <font color="#2040a0">pcgMode</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>         <font color="#444444">/* use rhs as initial guess for inner pcg iterations */</font>
<a name="line252">252</a>       <strong>int</strong> <font color="#2040a0">verbosity</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>       <font color="#444444">/* print iterations info */</font>
<a name="line253">253</a>       <strong>double</strong> <font color="#2040a0">tol</font> <font color="4444FF">=</font> <font color="#FF0000">1.e-8</font><font color="4444FF">;</font>      <font color="#444444">/* absolute tolerance (all eigenvalues) */</font>
<a name="line254">254</a>       <strong>int</strong> <font color="#2040a0">lobpcgSeed</font> <font color="4444FF">=</font> <font color="#FF0000">775</font><font color="4444FF">;</font>    <font color="#444444">/* random seed */</font>
<a name="line255">255</a> 
<a name="line256">256</a>       <font color="#2040a0">mv_MultiVectorPtr</font> <font color="#2040a0">eigenvectors</font> <font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">;</font>
<a name="line257">257</a>       <font color="#2040a0">mv_MultiVectorPtr</font> <font color="#2040a0">constraints</font> <font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">;</font>
<a name="line258">258</a>       <strong>double</strong> <font color="4444FF">*</font><font color="#2040a0">eigenvalues</font> <font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">;</font>
<a name="line259">259</a> 
<a name="line260">260</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">myid</font> <font color="4444FF">!</font><font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">)</font>
<a name="line261">261</a>          <font color="#2040a0">verbosity</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line262">262</a> 
<a name="line263">263</a>       <font color="#444444">/* define an interpreter for the ParCSR interface */</font>
<a name="line264">264</a>       <font color="#2040a0">interpreter</font> <font color="4444FF">=</font> <font color="#2040a0">hypre_CTAlloc</font><font color="4444FF">(</font><font color="#2040a0">mv_InterfaceInterpreter</font>,<font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line265">265</a>       <font color="#2040a0">HYPRE_ParCSRSetupInterpreter</font><font color="4444FF">(</font><font color="#2040a0">interpreter</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line266">266</a>       <font color="#2040a0">HYPRE_ParCSRSetupMatvec</font><font color="4444FF">(</font><font color="4444FF">&amp;</font><font color="#2040a0">matvec_fn</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line267">267</a> 
<a name="line268">268</a>       <font color="#444444">/* eigenvectors - create a multivector */</font>
<a name="line269">269</a>       <font color="#2040a0">eigenvectors</font> <font color="4444FF">=</font>
<a name="line270">270</a>          <font color="#2040a0">mv_MultiVectorCreateFromSampleVector</font><font color="4444FF">(</font><font color="#2040a0">interpreter</font>, <font color="#2040a0">blockSize</font>, <font color="#2040a0">par_x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line271">271</a>       <font color="#2040a0">mv_MultiVectorSetRandom</font> <font color="4444FF">(</font><font color="#2040a0">eigenvectors</font>, <font color="#2040a0">lobpcgSeed</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line272">272</a> 
<a name="line273">273</a>       <font color="#444444">/* eigenvectors - get a pointer */</font>
<a name="line274">274</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line275">275</a>          <font color="#2040a0">mv_TempMultiVector</font><font color="4444FF">*</font> <font color="#2040a0">tmp</font> <font color="4444FF">=</font> <font color="#2040a0">mv_MultiVectorGetData</font><font color="4444FF">(</font><font color="#2040a0">eigenvectors</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line276">276</a>          <font color="#2040a0">pvx</font> <font color="4444FF">=</font> <font color="4444FF">(</font><font color="#2040a0">HYPRE_ParVector</font><font color="4444FF">*</font><font color="4444FF">)</font><font color="4444FF">(</font><font color="#2040a0">tmp</font> <font color="4444FF">-</font><font color="4444FF">&gt;</font> <font color="#2040a0">vector</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line277">277</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line278">278</a> 
<a name="line279">279</a>       <font color="#444444">/* eigenvalues - allocate space */</font>
<a name="line280">280</a>       <font color="#2040a0">eigenvalues</font> <font color="4444FF">=</font> <font color="4444FF">(</font><strong>double</strong><font color="4444FF">*</font><font color="4444FF">)</font> <font color="#2040a0">calloc</font><font color="4444FF">(</font> <font color="#2040a0">blockSize</font>, <strong>sizeof</strong><font color="4444FF">(</font><strong>double</strong><font color="4444FF">)</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line281">281</a> 
<a name="line282">282</a>       <font color="#2040a0">HYPRE_LOBPCGCreate</font><font color="4444FF">(</font><font color="#2040a0">interpreter</font>, <font color="4444FF">&amp;</font><font color="#2040a0">matvec_fn</font>, <font color="4444FF">&amp;</font><font color="#2040a0">lobpcg_solver</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line283">283</a>       <font color="#2040a0">HYPRE_LOBPCGSetMaxIter</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font>, <font color="#2040a0">maxIterations</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line284">284</a>       <font color="#2040a0">HYPRE_LOBPCGSetPrecondUsageMode</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font>, <font color="#2040a0">pcgMode</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line285">285</a>       <font color="#2040a0">HYPRE_LOBPCGSetTol</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font>, <font color="#2040a0">tol</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line286">286</a>       <font color="#2040a0">HYPRE_LOBPCGSetPrintLevel</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font>, <font color="#2040a0">verbosity</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line287">287</a> 
<a name="line288">288</a>       <font color="#444444">/* use a preconditioner */</font>
<a name="line289">289</a>       <font color="#2040a0">HYPRE_LOBPCGSetPrecond</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font>,
<a name="line290">290</a>                              <font color="4444FF">(</font><font color="#2040a0">HYPRE_PtrToSolverFcn</font><font color="4444FF">)</font> <font color="#2040a0">HYPRE_BoomerAMGSolve</font>,
<a name="line291">291</a>                              <font color="4444FF">(</font><font color="#2040a0">HYPRE_PtrToSolverFcn</font><font color="4444FF">)</font> <font color="#2040a0">HYPRE_BoomerAMGSetup</font>,
<a name="line292">292</a>                              <font color="#2040a0">precond</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line293">293</a> 
<a name="line294">294</a>       <font color="#2040a0">HYPRE_LOBPCGSetup</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font>, <font color="4444FF">(</font><font color="#2040a0">HYPRE_Matrix</font><font color="4444FF">)</font><font color="#2040a0">parcsr_A</font>,
<a name="line295">295</a>                         <font color="4444FF">(</font><font color="#2040a0">HYPRE_Vector</font><font color="4444FF">)</font><font color="#2040a0">par_b</font>, <font color="4444FF">(</font><font color="#2040a0">HYPRE_Vector</font><font color="4444FF">)</font><font color="#2040a0">par_x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line296">296</a> 
<a name="line297">297</a>       <font color="#2040a0">time_index</font> <font color="4444FF">=</font> <font color="#2040a0">hypre_InitializeTiming</font><font color="4444FF">(</font><font color="#008000">&quot;LOBPCG Solve&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line298">298</a>       <font color="#2040a0">hypre_BeginTiming</font><font color="4444FF">(</font><font color="#2040a0">time_index</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line299">299</a> 
<a name="line300">300</a>       <font color="#2040a0">HYPRE_LOBPCGSolve</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font>, <font color="#2040a0">constraints</font>, <font color="#2040a0">eigenvectors</font>, <font color="#2040a0">eigenvalues</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line301">301</a> 
<a name="line302">302</a>       <font color="#2040a0">hypre_EndTiming</font><font color="4444FF">(</font><font color="#2040a0">time_index</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line303">303</a>       <font color="#2040a0">hypre_PrintTiming</font><font color="4444FF">(</font><font color="#008000">&quot;Solve phase times&quot;</font>, <font color="#2040a0">MPI_COMM_WORLD</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line304">304</a>       <font color="#2040a0">hypre_FinalizeTiming</font><font color="4444FF">(</font><font color="#2040a0">time_index</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line305">305</a>       <font color="#2040a0">hypre_ClearTiming</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line306">306</a> 
<a name="line307">307</a>       <font color="#444444">/* clean-up */</font>
<a name="line308">308</a>       <font color="#2040a0">HYPRE_BoomerAMGDestroy</font><font color="4444FF">(</font><font color="#2040a0">precond</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line309">309</a>       <font color="#2040a0">HYPRE_LOBPCGDestroy</font><font color="4444FF">(</font><font color="#2040a0">lobpcg_solver</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line310">310</a>       <font color="#2040a0">hypre_TFree</font><font color="4444FF">(</font><font color="#2040a0">eigenvalues</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line311">311</a>       <font color="#2040a0">hypre_TFree</font><font color="4444FF">(</font><font color="#2040a0">interpreter</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line312">312</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line313">313</a> 
<a name="line314">314</a>    <font color="#444444">/* Save the solution for GLVis visualization, see vis/glvis-ex11.sh */</font>
<a name="line315">315</a>    <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">vis</font><font color="4444FF">)</font>
<a name="line316">316</a>    <font color="4444FF"><strong>{</strong></font>
<a name="line317">317</a>       <font color="#2040a0">FILE</font> <font color="4444FF">*</font><font color="#2040a0">file</font><font color="4444FF">;</font>
<a name="line318">318</a>       <strong>char</strong> <font color="#2040a0">filename</font><font color="4444FF">[</font><font color="#FF0000">255</font><font color="4444FF">]</font><font color="4444FF">;</font>
<a name="line319">319</a> 
<a name="line320">320</a>       <strong>int</strong> <font color="#2040a0">nvalues</font> <font color="4444FF">=</font> <font color="#2040a0">local_size</font><font color="4444FF">;</font>
<a name="line321">321</a>       <strong>double</strong> <font color="4444FF">*</font><font color="#2040a0">values</font><font color="4444FF">;</font>
<a name="line322">322</a> 
<a name="line323">323</a>       <font color="#444444">/* get the local solution */</font>
<a name="line324">324</a>       <font color="#2040a0">values</font> <font color="4444FF">=</font> <font color="#2040a0">hypre_VectorData</font><font color="4444FF">(</font><font color="#2040a0">hypre_ParVectorLocalVector</font><font color="4444FF">(</font>
<a name="line325">325</a>                                    <font color="4444FF">(</font><font color="#2040a0">hypre_ParVector</font><font color="4444FF">*</font><font color="4444FF">)</font><font color="#2040a0">pvx</font><font color="4444FF">[</font><font color="#2040a0">blockSize</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line326">326</a> 
<a name="line327">327</a>       <font color="#2040a0">sprintf</font><font color="4444FF">(</font><font color="#2040a0">filename</font>, <font color="#008000">&quot;%s.%06d&quot;</font>, <font color="#008000">&quot;vis/ex11.sol&quot;</font>, <font color="#2040a0">myid</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line328">328</a>       <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">file</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font><font color="#2040a0">filename</font>, <font color="#008000">&quot;w&quot;</font><font color="4444FF">)</font><font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">)</font>
<a name="line329">329</a>       <font color="4444FF"><strong>{</strong></font>
<a name="line330">330</a>          <font color="#2040a0">printf</font><font color="4444FF">(</font><font color="#008000">&quot;Error: can't open output file %s<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">filename</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line331">331</a>          <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line332">332</a>          <font color="#2040a0">exit</font><font color="4444FF">(</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line333">333</a>       <font color="4444FF"><strong>}</strong></font>
<a name="line334">334</a> 
<a name="line335">335</a>       <font color="#444444">/* save solution */</font>
<a name="line336">336</a>       <strong>for</strong> <font color="4444FF">(</font><font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font> <font color="#2040a0">i</font> <font color="4444FF">&lt;</font> <font color="#2040a0">nvalues</font><font color="4444FF">;</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="4444FF">+</font><font color="4444FF">)</font>
<a name="line337">337</a>          <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">file</font>, <font color="#008000">&quot;%.14e<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">values</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line338">338</a> 
<a name="line339">339</a>       <font color="#2040a0">fflush</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line340">340</a>       <font color="#2040a0">fclose</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line341">341</a> 
<a name="line342">342</a>       <font color="#444444">/* save global finite element mesh */</font>
<a name="line343">343</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">myid</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">)</font>
<a name="line344">344</a>          <font color="#2040a0">GLVis_PrintGlobalSquareMesh</font><font color="4444FF">(</font><font color="#008000">&quot;vis/ex11.mesh&quot;</font>, <font color="#2040a0">n</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line345">345</a>    <font color="4444FF"><strong>}</strong></font>
<a name="line346">346</a> 
<a name="line347">347</a>    <font color="#444444">/* Clean up */</font>
<a name="line348">348</a>    <font color="#2040a0">HYPRE_IJMatrixDestroy</font><font color="4444FF">(</font><font color="#2040a0">A</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line349">349</a>    <font color="#2040a0">HYPRE_IJVectorDestroy</font><font color="4444FF">(</font><font color="#2040a0">b</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line350">350</a>    <font color="#2040a0">HYPRE_IJVectorDestroy</font><font color="4444FF">(</font><font color="#2040a0">x</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line351">351</a> 
<a name="line352">352</a>    <font color="#444444">/* Finalize MPI*/</font>
<a name="line353">353</a>    <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line354">354</a> 
<a name="line355">355</a>    <strong>return</strong><font color="4444FF">(</font><font color="#FF0000">0</font><font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line356">356</a> <font color="4444FF"><strong>}</strong></font>

</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
